@extends('admin/layout/master')
@section('title', '文章列表')
@section('title2', '文章列表')

@section('static')
	<script src="/plus/My97DatePicker/WdatePicker.js"></script>
@endsection

@section('action')
	<a class="layui-btn layui-btn-small layui-btn-normal usersAdd_btn" href="{{ url('/admin/article/create') }}"><i class="layui-icon"></i>文章添加</a>
	<!-- <a class="layui-btn layui-btn-small layui-btn-danger batchDel"><i class="layui-icon"></i>导出数据</a> -->
@endsection

@section('content')

	<form class="layui-field-box layui-form" action="{{ url('/admin/article/index') }}" method="get">
		<div class="layui-form-item">
			<label class="layui-form-label">搜索：</label>
			<div class="layui-inline">
				<input type="text" name="title" placeholder="文章标题" value="{{ $request->input('title') }}" autocomplete="off" class="layui-input">
			</div>
			<div class="layui-inline">
				<select name="type_id" lay-verify="">
					<option value="">所属栏目</option>
					@foreach($typeData as $v)
						<option value="{{$v['id']}}" <?php echo $v['id'] == $request->input('type_id') ? 'selected' : ''; ?> >{{$v['name']}}</option>
					@endforeach
				</select>
			</div>
			<div class="layui-inline">
				<select name="flag" lay-verify="">
					<option value="">选择标记</option>
					<option value="推荐">推荐</option>
					<option value="置顶">置顶</option>
					<option value="幻灯">幻灯</option>
					<option value="特荐">特荐</option>
					<option value="滚动">滚动</option>
				</select>
			</div>
			<div class="layui-inline">
				<select name="case_id">
					<option value="">选择专栏</option>
					@foreach($caseData as $v)
					<option value="{{ $v->id }}">{{ $v->name }}</option>
					@endforeach
				</select>
			</div>
			<div class="layui-inline">
				<input type="text" name="time1" placeholder="发布时间开始" value="{{ $request->input('time1') }}" autocomplete="off" class="layui-input" onclick="WdatePicker({readOnly:true})">
			</div>
			<div class="layui-inline">
				<input type="text" name="time2" placeholder="发布时间结束" value="{{ $request->input('time2') }}" autocomplete="off" class="layui-input" onclick="WdatePicker({readOnly:true})">
			</div>
			<button class="layui-btn"><i class="layui-icon"></i> </button>
			<a href="{{ url('/admin/article/index') }}" class="layui-btn layui-btn-primary">重置</a> </div>
	</form>

	<div class="layui-field-box layui-form">
		<form name="mainform" method="post" action="{{ url('/admin/article/dels') }}">
			<table class="layui-table" lay-size="sm">
				<thead>
				<tr>
					<th style="width: 30px;"><input type="checkbox" lay-filter="allselector" lay-skin="primary" id="qx">
						<div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div></th>
					<th style="width: 30px;">ID</th>
					<th>标题</th>
					<th style="width: 60px;">栏目</th>
					<th style="width: 40px;">类型</th>
					<th style="width: 80px;">tags</th>
					<th style="width: 80px;">所属专栏</th>
					<th style="width: 40px;">评论数</th>
					<th style="width: 120px;">添加时间</th>
					<th style="width: 85px;">操作</th>
				</tr>
				</thead>
				<tbody id="content">
				@foreach ($data as $v)
					<tr>
						<td>
							<input type="checkbox" name="ids[]" value="{{ $v->id }}" lay-skin="primary">
							<div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>
						</td>
						<td>{{ $v->id }}</td>
						<td><a href="{{ url('/article/'.$v->id) }}" style="color: #000;font-weight: bold;" target="_blank">{{ $v->title }}</a></td>
						<td>{{$v->types->name}}</td>
						<td>{{ $v->type == 2 ? "HTML" : "Makerdown" }}</td>
						<td>{{_articleTags($v->id)}}</td>
						<td><?php if(isset($v->cases->name)){echo $v->cases->name;} ?></td>
						<td>
							<a href="{{ url('/admin/comment/index?article_id='.$v->id) }}" style="color: #f60;">{{commentCount($v->id)}}</a>
						</td>
						<td>{{ $v->created_at }}</td>
						<td>
							<div class="layui-btn-group">
								<a href="{{ url('/admin/article/edit', array('id' => $v->id)) }}" class="layui-btn layui-btn-primary layui-btn-sm"> <i class="layui-icon">&#xe642;</i> </a>
								<a href="{{ url('/admin/article/destroy', array('id' => $v->id)) }}" onclick="return confirm('确定要删除吗？')" class="layui-btn layui-btn-primary layui-btn-sm"> <i class="layui-icon">&#xe640;</i> </a>
							</div>
						</td>
					</tr>
				@endforeach
				<tr>
					<td colspan="10" style="text-align: center;">
						{{ $data->links() }}
						<div style="display: inline-block;padding-left: 0;">
							第<span class="pagelink_cur_page">{{ $data->currentPage() }}</span>/<span class="pagelink_all_page">{{ $data->lastPage() }}</span>页&nbsp;每页<span class="pagelink_pagesize">{{ $data->perPage() }}</span>条&nbsp;共<span class="pagelink_all_rec">{{ $data->total() }}</span>条
						</div>
					</td>
				</tr>
				<tr>
					{{ csrf_field() }}
					<td colspan="10" align="center"><a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-mini" onclick="dels()">批量删除</a></td>
				</tr>
				</tbody>
			</table>
		</form>
	</div>
@endsection

@section('layuijs')
	<script>
		//一般直接写在一个js文件中
		layui.use(['layer', 'form'], function(){
			var layer = layui.layer
					,form = layui.form;
			form.on('checkbox(allselector)', function(data){
				var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
				child.each(function(index, item){
					item.checked = data.elem.checked;
				});
				form.render('checkbox');
			});
		});
	</script>
	<script>
		//删除
		function dels(){
			layer.confirm('是否批量删除?', {icon: 3, title:'提示'}, function(index){
				document.mainform.submit();
				layer.close(index);
			})
		};
	</script>
@endsection